<?php 
session_start();
require_once '../inc/conn.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>影歌科技OA系统</title>
<style type="text/css">
<!--
body,td,th {
	font-size: 12px;
	color: #3791cf;
}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>

<link href="user2/css/bg.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function check_reg()
{
  if(fr.yhm.value=="")
  {
     alert('管理帐号不能为空！');
	 fr.yhm.focus();
	 return false;
  }
 
  if(fr.yhxm.value=="")
  {
     alert('验证码不能为空！');
	 fr.yhxm.focus();
	 return false;
  }
  if(fr.mm.value=="")
  {
     alert('登录密码不能为空！');
	 fr.mm.focus();
	 return false
  }
  if((fr.mm.value)!=(fr.checkmm.value))
  {
     alert('确认密码与密码不符！');
	 fr.yhm.focus();
	 return false;
  }
  
  return true;
}
window.onload = function(){
document.getElementById("yh").focus();
}

</SCRIPT>
</script>


</head>

<body>
<form id="fr" name="fr" action="" method="post" onsubmit="return check(this);">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="45" valign="top">&nbsp;</td>
    <td width="623" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="../images/register_04.gif" width="623" height="135" /></td>
      </tr>
    </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td background="../images/register_28.gif">
            <table width="100%" height="158" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td align="center"><table width="272" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="123" height="25" align="left"><img src="../images/register_10.gif" width="79" height="17" /></td>
                    <td width="268" align="left"><label>
                      <input name="yhm" id="yhm" type="text" dataType="Limit" require="true" msg="用户名不能为空"  />
                    </label></td>
                  </tr>
                  <tr>
                    <td height="25" align="left"><img src="../images/register_13.gif" width="79" height="18" /></td>
                    <td align="left"><input  name="yhxm" id="yhxm" type="text" dataType="Limit" require="true" msg="用户姓名不能为空"  /></td>
                  </tr>
                  <tr>
                    <td height="25" align="left"><img src="../images/register_15.gif" width="79" height="17" /></td>
                    <td align="left"><input name="mm" id="mm" size="25" type="password" dataType="Limit" require="true" msg="密码不能为空"  /></td>
                  </tr>
                  <tr>
                    <td height="25" align="left"><img src="../images/register_17.gif" width="76" height="19" /></td>
                    <td align="left"><input name="checkmm" id="checkmm" size="25" type="password" dataType="Limit" require="true" msg="确认密码不能为空" /></td>
                  </tr>
                   <tr bgcolor="#FFFFFF">
				 <td align="left"  height="25"><font size=3><b>用户权限:</b></font></td>
                 <td  align="left"> 
                   <select name="prv_flag" id="select">
                             <option value="0" selected="selected">普通用户</option>
                             <option value="1">部门主管</option>
                             <option value="2">系统管理员</option>
                         </select>
                </td>
              </tr>
                </table></td>
                <td width="232" align="right" valign="top"><img src="../images/register_08.gif" width="232" height="172" /></td>
              </tr>
              
            
            </table>
        
            
        
                    <table width="623" height="41" border="0" cellpadding="0" cellspacing="0">
                      <tr >
			<td width="201">&nbsp;</td>
                        <td width="107"><input " type="submit" id ="sub" name="sub" value="注册" width="82" height="23" class="button" /></td>
                        <td width="62"><input  type="reset" value="取消" width="62" height="23" class="button"></td>
			<td width="201">&nbsp;</td>
                      </tr>
                    </table>                 
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="9"><img src="../images/register_31.gif" width="9" height="44" /></td>
          <td background="../images/register_32.gif">&nbsp;</td>
          <td width="11"><img src="../images/register_34.gif" width="11" height="44" /></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
    <td class="bg">&nbsp;</td>
  </tr>
</table>
</form>
<iframe id="ifr" name="ifr" style="display:none" ></iframe>
<?php

 if(isset($_POST["sub"])){
	$login_acc=@addslashes(trim($_POST["yhm"]));
	$username=@addslashes(trim($_POST["yhxm"]));
	$password=@md5(addslashes(trim($_POST["mm"])));
	$prv_flag = addslashes(trim($_POST["prv_flag"]));

	if(!empty($login_acc)&&!empty($password)){
		
		$sqlcheck="select * from login_user where user_acc='$login_acc'";
		$resultcheck=$oa->query($sqlcheck);
		$rowcheck=mysql_fetch_row($resultcheck);
		
		if(!$rowcheck){
			//$_SESSION["username"]=$username;
			$sqlreg="INSERT INTO login_user(user_acc,username,user_pwd,prv_flag) VALUES('$login_acc','$username','$password',$prv_flag)";
			$result_reg=$oa->query($sqlreg);
			if($result_reg){
			echo  "<script>alert('添加用户成功!'); window.location.href='user_list.php';</script>";
			}
		}
		else{
			echo "<font color=red><script>alert('已经存在该帐号，请换一个帐号!');</script></font>".mysql_error();
		}
      }

$oa->close_db();
}
?>
</body>
</html>
